#pragma once
#include <linux/futex.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <atomic>

namespace linkfabric {
inline int futex_wait(std::atomic<uint32_t>* addr, uint32_t expected) {
    return syscall(SYS_futex, reinterpret_cast<int*>(addr), FUTEX_WAIT, expected, nullptr, nullptr, 0);
}

inline int futex_wake(std::atomic<uint32_t>* addr, int count = 1) {
    return syscall(SYS_futex, reinterpret_cast<int*>(addr), FUTEX_WAKE, count, nullptr, nullptr, 0);
}
}